import type { Reducer, Effect } from 'umi';

import { getUserList, getOrgTree } from '@/services/userControl';


export type StateType = {
};

export type UserControlType = {
  namespace: string;
  state: StateType;
  effects: {
    getUserList: Effect;
    getOrgTree:Effect
    // logout: Effect;
  };
  reducers: {

  };
};

const UserControl: UserControlType = {
  namespace: 'userControl',

  state: {

  },

  effects: {
    *getUserList({ payload, callback, onerror }, { call, put }) {
      try {
        const response = yield call(getUserList, payload);
        callback(response);
      } catch (error) {
        onerror(error);
      }
    },
    *getOrgTree({ payload, callback, onerror }, { call, put }) {
      try {
        const response = yield call(getOrgTree, payload);
        console.log(response)
        // callback(response);
        return Promise.resolve(response)
      } catch (error) {
        onerror(error);
      }
    },
  },

  reducers: {},
};

export default UserControl;
